﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace personalplaner.common.controls
{
	public class PrintPreviewItem : ContentControl
	{
		static PrintPreviewItem()
        {
			DefaultStyleKeyProperty.OverrideMetadata(typeof(PrintPreviewItem), new FrameworkPropertyMetadata(typeof(PrintPreviewItem)));
        }

		internal void Unfocus()
		{
			IsSelected = false;
		}

		internal void SetFocus()
		{
			//bool returnValue = false;

			//if (!GetBoolField(BoolField.SettingFocus))
			//{
			//    TabItem currentFocus = Keyboard.FocusedElement as TabItem;

			//    // If current focus was another TabItem in the same TabControl - dont set focus on content 
			//    bool setFocusOnContent = ((currentFocus == this) || (currentFocus == null) || (currentFocus.TabControlParent != this.TabControlParent));
			//    SetBoolField(BoolField.SettingFocus, true);
			//    SetBoolField(BoolField.SetFocusOnContent, setFocusOnContent);
			//    try
			//    {
			//        returnValue = Focus() || setFocusOnContent;
			//    }
			//    finally
			//    {
			//        SetBoolField(BoolField.SettingFocus, false);
			//        SetBoolField(BoolField.SetFocusOnContent, false);
			//    }
			//}

			//return returnValue;
			
			Focus();
			IsSelected = true;
		}

		///// <summary>
		///// This is the method that responds to the MouseLeftButtonDownEvent event. 
		///// </summary>
		///// <param name="e"></param>
		//protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
		//{
		//    // We should process only the direct events in case TabItem is the selected one
		//    // otherwise we are getting this event when we click on TabItem content because it is in the logical subtree 
		//    if (e.Source == this || !IsSelected)
		//    {
		//        if (SetFocus())
		//            e.Handled = true;
		//    }
		//    base.OnMouseLeftButtonDown(e);
		//} 

		#region Properties

		public bool IsSelected
		{
			get
			{
				return (bool)GetValue(IsSelectedProperty);
			}
			set
			{
				SetValue(IsSelectedProperty, value);
			}
		}

		public static readonly DependencyProperty IsSelectedProperty =
			DependencyProperty.Register("IsSelected", typeof(bool), typeof(PrintPreviewItem), new PropertyMetadata(false));


		#endregion
	}
}
